using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using JGSY.CMS.LowCode.Platform.Infrastructure.Extensions;
using JGSY.CMS.LowCode.Platform.Infrastructure.Configuration;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules.Modules
{
    /// <summary>
    /// 核心基础服务模块
    /// 包含控制器、健康检查、HTTP上下文访问等基础服务
    /// </summary>
    public class CoreServicesModule : IServiceModule
    {
        public string ModuleName => "核心基础服务";
        public int Priority => 1; // 最高优先级
        public bool LoadInFastMode => true; // 快速模式必须加载
        public ModulePermission RequiredPermission => ModulePermission.CoreServices;
        public bool IsCriticalModule => true; // 始终关键

        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            // MVC 控制器
            services.AddControllers();
            
            // 健康检查
            services.AddHealthChecks();
            
            // HTTP上下文访问器
            services.AddHttpContextAccessor();
            
            // 配置管理服务
            services.AddAppConfiguration();
            services.AddConfigurationMapping(configuration);
        }

        public void ConfigureMinimalServices(IServiceCollection services, IConfiguration configuration)
        {
            // 核心模块的精简版本与完整版本相同，因为都是必需的基础服务
            ConfigureServices(services, configuration);
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 核心服务无特殊配置要求，始终返回true
            return true;
        }
    }
}
